<?xml version="1.0" encoding="UTF-8"?>
<ui:composition template="/pages/mastertemplate/MasterPage.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" 
	xmlns:syn="http://www.syniverse.com">
	<ui:define name="content">
		<p:panel header="#{msg.vthh_title}">
			<h:form>
				<p:fileUpload widgetVar="fileuplaod_wgt"
					fileUploadListener="#{VatTuHangHoaBean.handleFileUpload}"
					mode="advanced" dragDropSupport="false" update=":vthhForm"
					sizeLimit="100000" fileLimit="1"
					allowTypes="/(\.|\/)(#{DataConfigBean.fileExtensionPattern})$/" />
			</h:form>
			<h:form>
				<p:commandButton style="width:150px;float: left;margin-top:10px;"
					value="#{msg.Button_export}"
					actionListener="#{VatTuHangHoaBean.downloadFileCSV}" ajax="false">
					<p:fileDownload value="#{VatTuHangHoaBean.file}" />
				</p:commandButton>
			</h:form>

			<h:form id="vthhForm">
				<p:growl id="growforFile" autoupdate="true"
					life="#{DataConfigBean.growlShow}" />
				<p:dataTable id="dataTable" var="vthh"
					value="#{VatTuHangHoaBean.vthhModel}" lazy="true" paginator="true"
					rows="10"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					rowsPerPageTemplate="10,20,50,100"
					style="width: 100%; margin: 45px auto;">

					<f:facet name="header">
						<h:outputText value="#{msg.danhsachvthh}" styleClass="tableHeader" />
						<div style="margin: -4px -11px 5px; float: right;">
							<p:commandButton style="height: 25px"
								update=":addvthhForm:display" value="+ thêm mới"
								rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
								actionListener="#{VatTuHangHoaBean.notifyAdd}"
								onclick="PF('vthhDialog').show();">
							</p:commandButton>
						</div>

					</f:facet>

					<p:column headerText="#{msg.mavthh}" filterBy="#{vthh.maVTHH}"
						filterMatchMode="contains" >#{vthh.maVTHH}  </p:column>

					<p:column headerText="#{msg.tenvthh}" filterBy="#{vthh.tenVTHH}"
						filterMatchMode="contains">  #{vthh.tenVTHH}   </p:column>

					<p:column headerText="#{msg.loaivthh}" filterBy="#{vthh.loaiVTHH}"
						filterMatchMode="contains">  #{vthh.loaiVTHH}   </p:column>

					<p:column style="width:60px;text-align: center;"
						headerText="#{msg.table_actions}">
						<p:commandButton styleClass="smallButton"
							icon="ui-icon ui-icon-pencil" update=":addvthhForm:display"
							rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
							action="#{VatTuHangHoaBean.notifyEdit(vthh)}"
							oncomplete="PF('vthhDialog').show();">

						</p:commandButton>
						<p:commandButton style="margin-left: 5px" styleClass="smallButton"
							icon="ui-icon ui-icon-trash"
							rendered="#{UserBean.getAccessLevel() == 'WRITE'}"
							oncomplete="PF('confirmRemove').show();">
							<f:setPropertyActionListener value="#{vthh}"
								target="#{VatTuHangHoaBean.selectedvthh}" />
						</p:commandButton>
					</p:column>

				</p:dataTable>

				<p:dialog id="confirmRemove" header="#{msg.confirm}"
					widgetVar="confirmRemove" resizable="false">
					<table>
						<tr>
							<td><h:outputText value="#{msg.confirm_text}:" /></td>
							<td align="right"><p:commandButton value="#{msg.okButton}"
									actionListener="#{VatTuHangHoaBean.removevthh}"
									update=":vthhForm" oncomplete="PF('confirmRemove').hide();" /></td>
						</tr>

					</table>
				</p:dialog>
			</h:form>
			<h:form id="addvthhForm">
				<p:dialog id="dialog" header="Thêm mới/ Sửa" modal="true"
					widgetVar="vthhDialog" resizable="false">

					<p:panel id="display">
						<table>
							<tr>
								<td><p:outputLabel style="margin-left: 20px" for="mavthh"
										value="#{msg.mavthh}" /></td>
								<td><p:inputText styleClass="inputText" required="true"
										requiredMessage="#{msg.mavthh}: #{msg.valuerequired}"
										id="mavthh" value="#{VatTuHangHoaBean.vthh.maVTHH}">

									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px" for="tenvthh"
										value="#{msg.tenvthh}" /></td>
								<td><p:inputText styleClass="inputText" required="true"
										requiredMessage="#{msg.tenvthh}: #{msg.valuerequired}"
										id="tenvthh" value="#{VatTuHangHoaBean.vthh.tenVTHH}">

									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.tinhchat}" /></td>
								<td><p:selectOneMenu styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.tinhchat}">
										<f:selectItems value="#{VatTuHangHoaBean.listTinhChatVTHH}"
											var="selectItem" itemLabel="#{selectItem}"
											itemValue="#{selectItem}" />
									</p:selectOneMenu></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.loaivthh}" /></td>
								<td><p:selectOneMenu styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.loaiVTHH}" filter="true"
										filterMatchMode="contains">
										<f:selectItems value="#{LoaiVTHHBean.listloaivthh}"
											var="selectItem" itemLabel="#{selectItem.tenLoai}"
											itemValue="#{selectItem.maLoai}" />
									</p:selectOneMenu></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.donvitinh}" /></td>
								<td><p:selectOneMenu styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.donViTinh}">
										<f:selectItems value="#{VatTuHangHoaBean.listDonViTinh}"
											var="selectItem" itemLabel="#{selectItem}"
											itemValue="#{selectItem}" />
									</p:selectOneMenu></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.thoigianbaohanh}" /></td>
								<td><p:calendar style="min-width:140px"
										value="#{VatTuHangHoaBean.vthh.thoiGianBaoHanh}"
										pattern="#{DataConfigBean.datepattern}" showButtonPanel="true">
										<syn:convertTimestamp pattern="#{DataConfigBean.datepattern}" />
									</p:calendar></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.dongiamua}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.donGiaMua}">

									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.dongiaban}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.donGiaBan}">
									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.nhacungcap}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.nhaCungCap}">
									</p:inputText></td>
								
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.tKChiPhi}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.tKChiPhi}">
									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.chietKhauMuaHang}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.chietKhauMuaHang}">
									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.dienGiaiMua}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.dienGiaiMua}">
									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.dienGiaiBan}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.dienGiaiBan}">
									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.nguonGoc}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.nguonGoc}">
									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.thueSuat}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.thueSuat}">

									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.taiKhoanKho}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.taiKhoanKho}">
									</p:inputText></td>
							</tr>
							<tr>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.tKDoanhThu}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.tKDoanhThu}">

									</p:inputText></td>
								<td><p:outputLabel style="margin-left: 20px"
										value="#{msg.chietKhauBanHang}" /></td>
								<td><p:inputText styleClass="inputText"
										value="#{VatTuHangHoaBean.vthh.chietKhauBanHang}">

									</p:inputText></td>
							</tr>
							<tr>
								<td></td>
								<td></td>

								<td></td>
								<td align="right"><p:commandButton value="Lưu"
										actionListener="#{VatTuHangHoaBean.save}"
										update=":vthhForm :addvthhForm:display"
										oncomplete="if(args.opSuccess) PF('vthhDialog').hide()"></p:commandButton></td>
							</tr>
						</table>
					</p:panel>
				</p:dialog>
			</h:form>
		</p:panel>
	</ui:define>
</ui:composition>
